#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h> 

#define DS1307      0xD0 >> 1                   // shift required by Wire.h
#define R_SECS      0
#define R_MINS      1
#define R_HRS       2
#define R_WKDAY     3
#define R_DATE      4
#define R_MONTH     5
#define R_YEAR      6
#define R_SQW       7


const int STATUS_LED =6; //D6  ( should be 6)

const int P40 = 21; //Relay Out B1
const int P41 = 22; //Relay Out B2
const int P42 = 23; //Relay Out B3
const int P43 = 24; //Relay Out B4
const int P44 = 25; //Relay Out B5
const int P45 = 26; //Relay Out B6

const int P11 = 7;  //Digital Input D7
const int P12 = 8;  //Digital Input E0
const int P13 = 9;  //Digital Input E1
const int P32 = 17;  //Digital Input C7
const int P33 = 16;  //Digital Input C6
const int P34 = 15;  //Digital Input C5
const int P35 = 14;  //Digital Input C4
const int P36 = 13;  //Digital Input C3
const int P37 = 12;  //Digital Input C2
const int P38 = 11;  //Digital Input C1
const int P39 = 10;  //Digital Input C0

const int ADC0_P24 = 38; //Analog Input F0
const int ADC1_P25 = 39; //Analog Input F1
const int ADC2_P26 = 40; //Analog Input F2
const int ADC3_P27 = 41; //Analog Input F4
const int ADC4_P28 = 42; //Analog Input F5
const int ADC5_P29 = 43; //Analog Input F6
const int ADC6_P30 = 45; //Analog Input F7
const int ADC7_P31 = 46; //Analog Input F8

const int SCL_P8 = 0; //I2C clock pin D4  // had to swap i2c with highcount pins
const int SDA_P9 = 0; //I2C data pin D5 // had to swap i2c with highcount pins

const int HCNT0 = 4; //High Speed counter 0  D0
const int HCNT1 = 5; //High Speed counter 0  D1

byte second = 0x00;                             // default to 01 JAN 2007, midnight
byte minute = 0x30;
byte hour = 0x15;
byte wkDay = 0x02;
byte day = 0x07;
byte month = 0x04;
byte year = 0x09;
byte ctrl = 0x00;

String time = "";
int current_position = 32765;
byte lowByte;
byte highByte;

int rtc[7];
byte data[56];



boolean oneshot = false; //first pass trigger

void setup() {
  Serial.begin(9600); // USB is always 12 Mbit/sec
  pinMode(STATUS_LED, OUTPUT);
  pinMode(P40, OUTPUT); 
  
  if(!oneshot)
  {
    SRAMWriteInt(1, 50000);
    oneshot = true;
    Serial.print(SRAMReadInt(1),DEC);
    Serial.println();
  }
}


